package com.dengyuanke.upms.controller;


import com.dengyuanke.upms.common.result.R;
import com.dengyuanke.upms.dto.TreeNode;
import com.dengyuanke.upms.entity.Menu;
import com.dengyuanke.upms.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author dengyuanke
 * @since 2019-06-29
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private IMenuService menuService;

    /**
     * 返回当前用户的树形菜单集合
     *
     * @return 当前用户的树形菜单
     */
    @GetMapping
    public R getUserMenu(String userId){
       List<TreeNode> menus= menuService.findMenusByUserId(userId);
        return R.success();
    }

    /**
     * 新增菜单
     *
     * @param menu 菜单信息
     * @return success/false
     */
    @PostMapping
    public R save(@Valid @RequestBody Menu menu) {
        return R.success(menuService.save(menu));
    }

    /**
     * 更新菜单
     *
     * @param menu
     * @return
     */
    @PutMapping
    public R update(@Valid @RequestBody Menu menu) {
        return R.success(menuService.updateById(menu));
    }
}

